package API.File.Practise.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Testconcat {
    public static void main(String[] args) {
        Map<String, Integer> map1 = new HashMap<>();
        Map<String, Integer> map2 = new HashMap<>();
        map2.put("a", 1);
        concat(map1, map2).forEach((String key, Integer value) -> {
            System.out.println(key + " : " + value);
        });
    }

    public static Map<String, Integer> concat(Map<String, Integer> a, Map<String, Integer> b) {
        Set<Map.Entry<String, Integer>> mapSet = b.entrySet();
        for (Map.Entry<String, Integer> entry : mapSet) {
            if (judgeIfExists(a, entry.getKey())) {
                a.put(entry.getKey(), a.get(entry.getKey()) + entry.getValue());
            } else {
                a.put(entry.getKey(), entry.getValue());
            }
        }
        return a;
    }

    public static boolean judgeIfExists(Map<String, Integer> map, String fileType) {
        if(map.containsKey(fileType)) {
            return true;
        } else {
            return false;
        }
    }
}
